package com.zhongkai.model3;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.codehaus.jackson.annotate.JsonBackReference;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;

@Entity
@Table(name = "menus",    catalog = "")
public class Menus implements Serializable {
    private Integer number;
    private String mName;
    private String mIcon;
    private String mUrl;
    private Integer elderMennus;
    private Collection<MenusRole> menusRolesByNumber;

    @Id
    @GenericGenerator(name = "generator", strategy = "increment")
    @GeneratedValue(generator = "generator")
    @Column(name = "number")
    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    @Basic
    @Column(name = "m_name")
    public String getmName() {
        return mName;
    }

    public void setmName(String mName) {
        this.mName = mName;
    }

    @Basic
    @Column(name = "m_icon")
    public String getmIcon() {
        return mIcon;
    }

    public void setmIcon(String mIcon) {
        this.mIcon = mIcon;
    }

    @Basic
    @Column(name = "m_url")
    public String getmUrl() {
        return mUrl;
    }

    public void setmUrl(String mUrl) {
        this.mUrl = mUrl;
    }

    @Basic
    @Column(name = "elder_mennus")
    public Integer getElderMennus() {
        return elderMennus;
    }

    public void setElderMennus(Integer elderMennus) {
        this.elderMennus = elderMennus;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Menus menus = (Menus) o;
        return Objects.equals(number, menus.number) &&
                Objects.equals(mName, menus.mName) &&
                Objects.equals(mIcon, menus.mIcon) &&
                Objects.equals(mUrl, menus.mUrl) &&
                Objects.equals(elderMennus, menus.elderMennus);
    }

    @Override
    public int hashCode() {

        return Objects.hash(number, mName, mIcon, mUrl, elderMennus);
    }

    @JsonBackReference
    @JsonIgnore
    @OneToMany(mappedBy = "menusByNumber")
    public Collection<MenusRole> getMenusRolesByNumber() {
        return menusRolesByNumber;
    }

    public void setMenusRolesByNumber(Collection<MenusRole> menusRolesByNumber) {
        this.menusRolesByNumber = menusRolesByNumber;
    }
}
